package com.tdkj.action.backstage.information;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tdkj.action.BaseAction;
import com.tdkj.model.information.BeanBaseInfo;
import com.tdkj.model.information.BeanInfoModule;
import com.tdkj.model.information.BeanModuleColumn;
import com.tdkj.model.user.BeanAdmin;
import com.tdkj.service.information.IBeanBaseInfoService;
import com.tdkj.service.information.IBeanInfoModuleService;
public class BaseInfoAction  extends BaseAction{
	private long id;
	private String mn;
	private String mt;
	private String cn;
	private String ct;
	private String title;
	private String resource;
	private String content;
	private String[] ids;
	private String varietyid;
	private String variety;
	private Map<String,String>prop=new HashMap<String,String>();
	private BeanBaseInfo info;
	private List<BeanModuleColumn> columns=new ArrayList<BeanModuleColumn>();
	private IBeanBaseInfoService baseInfoService;
	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}
	public long getId() {
		return id;
	}
	public String getVarietyid() {
		return varietyid;
	}

	public void setVarietyid(String varietyid) {
		this.varietyid = varietyid;
	}

	public String getVariety() {
		return variety;
	}

	public void setVariety(String variety) {
		this.variety = variety;
	}

	public void setId(long id) {
		this.id = id;
	}
	public String getMn() {
		return mn;
	}
	public void setMn(String mn) {
		this.mn = mn;
	}
	public String getMt() {
		return mt;
	}
	public void setMt(String mt) {
		this.mt = mt;
	}
	public String getCn() {
		return cn;
	}
	public void setCn(String cn) {
		this.cn = cn;
	}
	public String getCt() {
		return ct;
	}
	public void setCt(String ct) {
		this.ct = ct;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getResource() {
		return resource;
	}
	public void setResource(String resource) {
		this.resource = resource;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Map<String, String> getProp() {
		return prop;
	}
	public void setProp(Map<String, String> prop) {
		this.prop = prop;
	}
	public BeanBaseInfo getInfo() {
		return info;
	}
	public void setInfo(BeanBaseInfo info) {
		this.info = info;
	}
	public List<BeanModuleColumn> getColumns() {
		return columns;
	}
	public void setColumns(List<BeanModuleColumn> columns) {
		this.columns = columns;
	}
	@Resource
	public void setBaseInfoService(IBeanBaseInfoService baseInfoService) {
		this.baseInfoService = baseInfoService;
	}
	//获取信息列表
	public String findList(){
		Criteria criteria = this.createCriteria(BeanBaseInfo.class);
		//6911
		String[] l={"1","2","3","4","5","7","8","10","12","13"};
		criteria.add(Restrictions.in("moduletype", l));
		criteria.addOrder(Order.desc("moduletype"));// 
		this.queryByPage(criteria, "baseInfoAction!findList.action", 10);
		return "list";
	}
	//获取信息列表
	public String deleteInfo(){
		baseInfoService.delete(this.getId(), BeanBaseInfo.class);
		return findList();
	}
	public String updateStatus(){
		BeanBaseInfo bean=baseInfoService.findById(this.getId(), BeanBaseInfo.class);
		bean.setStatus("已审核");
		baseInfoService.saveOrUpdate(bean, BeanBaseInfo.class);
		return findList();
	}
	public String findEditPage(){
		String location=getLocation();
		info=baseInfoService.findById(this.getId(), BeanBaseInfo.class);
		System.out.println(info.getProp());
		return location+"_edit";
	}
	public String editInfo(){
		BeanBaseInfo info=baseInfoService.findById(this.getId(), BeanBaseInfo.class);
		if(this.getTitle().equals("")) {
			this.addFieldError("titleVlidate", "标题不能为空");
		}
		if(this.getTitle()!=null)info.setTitle(this.getTitle());
		if(this.getContent()!=null)info.setContent(this.getContent());
		if(this.getMn()!=null)info.setModulename(this.getMn());
		if(this.getMt()!=null)info.setModuletype(this.getMt());
		if(this.getCn()!=null)info.setColumnname(this.getCn());
		if(this.getCt()!=null)info.setColumntype(this.getCt());
		if(this.getVariety()!=null)info.setVariety(this.getVariety());
		if(this.getVarietyid()!=null)info.setVarietyid(this.getVarietyid());
		if(this.getMt()!=null)mt=this.getMt();
		if(this.getCt()!=null)ct=this.getCt();
		if(this.getMn()!=null)mn=this.getMn();
		if(this.getCn()!=null)cn=this.getCn();
		if(this.getResource()!=null)info.setResource(this.getResource());
		//info.setUser(u);
		if(this.getProp()!=null){
			info.setProp(this.getProp());
		}
		baseInfoService.saveOrUpdate(info, BeanBaseInfo.class);
		return findList();
	}
	private String getLocation() {
		String location="page";
		if(mt.equals("1")){location="1page";}
		if(mt.equals("3")&&(ct.equals("3")||ct.equals("4"))){location="334page";}
		if(mt.equals("7")){location="7page";}
		return location;
	}
	public String deleteAll() {
		String mt=this.getMt();
		if (null != ids) {
			for (String idtemp : ids) {
				this.getBaseService().delete(Long.parseLong(idtemp), BeanBaseInfo.class);
			}
		}
		return findList();
	}

}
